package com.verlet.springbootdemo.execption;

import com.verlet.springbootdemo.common.ResponseCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 业务异常
 *
 * @author verlet
 * @date 2021-02-27 01:14
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BizException extends RuntimeException {

    private final int code;

    /**
     * 无参默认构造ERROR
     */
    public BizException() {
        super(ResponseCode.ERROR.getDesc());
        this.code = ResponseCode.ERROR.getCode();
    }

    /**
     * 指定错误码构造通用异常
     */
    public BizException(final ResponseCode responseCode) {
        super(responseCode.getDesc());
        this.code = responseCode.getCode();
    }

    /**
     * 指定详细描述构造通用异常
     *
     * @param detailedMessage 详细描述
     */
    public BizException(final String detailedMessage) {
        super(detailedMessage);
        this.code = ResponseCode.ERROR.getCode();
    }

    /**
     * 指定导火索构造通用异常
     *
     * @param t 导火索
     */
    public BizException(final Throwable t) {
        super(t);
        this.code = ResponseCode.ERROR.getCode();
    }

    /**
     * 构造通用异常
     */
    public BizException(final ResponseCode responseCode, final String detailedMessage) {
        super(detailedMessage);
        this.code = responseCode.getCode();
    }

    /**
     * 构造通用异常
     */
    public BizException(final ResponseCode responseCode, final Throwable t) {
        super(responseCode.getDesc(), t);
        this.code = responseCode.getCode();
    }

    /**
     * 构造通用异常
     *
     * @param detailedMessage 详细描述
     * @param t               导火索
     */
    public BizException(final String detailedMessage, final Throwable t) {
        super(detailedMessage, t);
        this.code = ResponseCode.ERROR.getCode();
    }

    /**
     * 构造通用异常
     */
    public BizException(final ResponseCode responseCode, final String detailedMessage,
                        final Throwable t) {
        super(detailedMessage, t);
        this.code = responseCode.getCode();
    }
}